package com.dslu.fx.jobs;

import com.dslu.fx.domain.DzpAreaDO;
import com.dslu.fx.service.DzpAreaService;
import com.dslu.fx.service.StockBillService;
import com.dslu.fx.utils.CheckEmptyUtil;
import com.dslu.fx.vo.ProdVO;
import onbon.y2.Y2Exception;
import onbon.y2.Y2Screen;
import onbon.y2.play.MarqueeArea;
import onbon.y2.play.ProgramPlayFile;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.List;

@Component
public class DzpJob {

    @Autowired
    private DzpAreaService dzpAreaService;


    @Autowired
    private StockBillService stockBillService;

    private void process() throws Y2Exception {
        List<DzpAreaDO> dzpAreaList = dzpAreaService.getDzpAreaListByCode("ZQBZ");
        for (DzpAreaDO dzpAreaDO : dzpAreaList) {
            showStock(dzpAreaDO);
        }
    }

    private void showStock(DzpAreaDO dzpAreaDO) throws Y2Exception {
        List<ProdVO> prodVO = stockBillService.getStockByAreaId(dzpAreaDO.getAreaId());
        if(CheckEmptyUtil.isNotEmpty(prodVO)){
            Y2Screen screen = getScreenByIp(dzpAreaDO.getIp());

        }
    }


    public Y2Screen getScreenByIp(String ip) throws Y2Exception {
        Y2Screen screen = new Y2Screen(ip);
        screen.login("guest", "guest");
        screen.clearPlayResources();//清除播放资源（删除播放节目）
        return screen;
    }

    public  void send(Y2Screen screen,List<String> list){
        try {
            //字幕区
            //字幕区是一个单行文字的分区，将内容以水平移动的方式显示在屏幕上
            MarqueeArea area = new MarqueeArea(0,0,64,64);
            area.right2Left(true);

            ProgramPlayFile pr = new ProgramPlayFile(1);
            pr.getAreas().add(area);

            String listId = screen.writePlaylist(pr);

            screen.play(listId);
        }catch (Exception e){
            e.printStackTrace();
        }

    }

}
